package com.andy.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.andy.dao.base.BaseHibernateDAO;
import com.andy.entity.ExamTest;

@Repository
public class ExamTestDAO extends BaseHibernateDAO<ExamTest> implements IExamTestDAO {

	@Override
	@SuppressWarnings("unchecked")
	public List<Integer> getTestIdByType(Integer subId, Integer testType) {
		String hql = "select t.id from ExamTest t where t.subId = :subId and t.examTestType.id = :testType ";
		return this.createQuery(hql)
					.setInteger("subId", subId)
					.setInteger("testType", testType)
					.list();
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<ExamTest> getTestListByIds(List<Integer> ids) {
		String hql = "from ExamTest t where t.id in (:ids) ";
		return this.createQuery(hql)
					.setParameterList("ids", ids)
					.list();
		
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<ExamTest> getTestListBySubAndTestType(Integer subId,
			Integer testTypeId) {
		String hql = "from ExamTest t where t.subId = :subId and t.examTestType.id = :testTypeId";
		return this.createQuery(hql)
					.setInteger("subId", subId)
					.setInteger("testTypeId", testTypeId)
					.list();
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<ExamTest> getTestListByIdList(List<Integer> randomTestIdList) {
		String hql = "from ExamTest t where t.id in (:randomTestIdList)";
		if (randomTestIdList != null && randomTestIdList.size() > 0) {
			return this.createQuery(hql).setParameterList("randomTestIdList", randomTestIdList).list();
		} else {
			return null;
		}
	}
	
}
